package cn.itsource.basic.service.impl;


import cn.itsource.basic.mapper.BaseMapper;
import cn.itsource.basic.query.BaseQuery;
import cn.itsource.basic.service.BaseService;
import cn.itsource.basic.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findOne(Long id) {
        return baseMapper.findOne(id);
    }

    @Transactional
    @Override
    public void add(T t) {
        baseMapper.add(t);
     
    }
    

    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Transactional
    @Override
    public void patchdel(Long[] ids) {
        baseMapper.patchdel(ids);
    }

    @Override
    public PageResult<T> queryPage(BaseQuery query) {
        Integer totals = baseMapper.queryCount(query);
        List<T> list = baseMapper.queryData(query);
        return new PageResult<T>(totals,list);
    }

    
}
